package ca.jerg.data;

import java.util.ArrayList;
import java.util.Iterator;

public class ErgDataRamp implements IErgDataShape
{
	public static void main( String[] args )
	{
		ErgDataRamp edr = new ErgDataRamp(10.0,100,15.0,500);
		edr.write();
		System.out.println("data points = " + edr.getNumberOfPoints());
		
		edr.setData(FIRST,400.0,600);
		edr.write();
		System.out.println(edr.getData() == null);
	}
	public ErgDataRamp( double startTime, int startWatts, double endTime, int endWatts )
	{
		data = new ArrayList<ErgPoint>();
		
		ErgPoint ep = new ErgPoint(startTime,startWatts);
		data.add(ep);
		
		ep = new ErgPoint(endTime,endWatts);
		data.add(ep);
	}
	
	//@Override
	public int getNumberOfPoints()
	{
		return data.size();
	}

	//@Override
	public ErgPoint getPoint( int index )
	{	
		if ( index > data.size() - 1 )
			return null;
		
		if ( index == LAST )
			index = data.size() - 1;
		
		return data.get(index);
	}

	//@Override
	public ArrayList<ErgPoint> getData()
	{	
		return data;
	}
	
	//@Override
	public boolean setData( int index, double time, int watts )
	{		
		if ( index > 1 )
			return false;
						
		ErgPoint ep = data.get(index);
		ep.setTime(time);
		ep.setWatts(watts);
		
		return true;
	}

	//@Override
	public boolean setData( int index, ErgPoint point )
	{	
		if ( index > (data.size() - 1) )
			return false;
		
		ErgPoint ep = data.get(index);
		ep.setTime(point.getTime());
		ep.setWatts(point.getWatts());
		
		return true;
	}

	//@Override
	public void write()
	{		
		Iterator i = data.iterator();
		
		while ( i.hasNext() )
		{
			ErgPoint ep = (ErgPoint)i.next();
			ep.write();
		}
	}

	private ArrayList<ErgPoint> data;
}
